#include "EquationSolver.h"
const double L = 10, r = 1, V = 12.4;
using namespace std;

class Func : public Function
{
public:
    double operator()(double _x);
    double diff(double _x);
};

//定义函数
double Func::operator()(double _x){
    double f;
    f = V - L * (0.5 * M_PI * r * r - r * r * asin(_x / r) - _x * sqrt(r * r - _x * _x));
    return f;
}

//定义函数对应的导数
double Func::diff(double _x){
    double f;
    f = -L * (-r / sqrt(1 - pow(_x / r, 2)) - sqrt(r * r - _x * _x) + _x * _x / sqrt(r * r - _x * _x));
    return f;
}

int main(int argc,char *argv [ ]){
    cout << "E:" << endl;
    Func func;
    Bisection bisec(0, r, 0.01, 100, func);
    Newton newton(0.5 * r, 0.01, 100, func);
    Secant sec(0, r, 0.01, 100, func);
    double root1 = bisec.solve(), root2 = newton.solve(), root3 = sec.solve();
    cout << "The root obtained by the bisection method is: " << root1 << " The  f(root) is: " << func(root1) << endl;
    cout << "The root obtained by Newton's method is: " << root2 << " The  f(root) is: " << func(root2) << endl;
    cout << "The root obtained by the secant method is: " << root3 << " The  f(root) is: " << func(root3) << endl;
    return 0;
}
